﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Vortex.SceneFramework.CSS {

	/// <summary>
	/// Style value key. It allows to improve access style properties with caching all of internal information.
	/// </summary>
	public class StyleKey {
		private string _name;
		private int _index;
		private Type _type;

		/// <summary>
		/// Initializes a new instance of the <see cref="StyleKey"/> class.
		/// </summary>
		/// <param name="name">The name of style property.</param>
		public StyleKey(string name) {
			if (null == name) throw new ArgumentNullException("name");
			_name = name;
			_index = StyleSheet.IndexOf(name);
		}

		/// <summary>
		/// Gets the style property name.
		/// </summary>
		/// <value>The name of style property.</value>
		public string Name {
			get { return _name; }
		}

		/// <summary>
		/// Gets the index of style property.
		/// </summary>
		/// <value>The index of style property.</value>
		public int Index {
			get { return _index; }
		}

		/// <summary>
		/// Gets the type of style property.
		/// </summary>
		/// <value>The type of style property.</value>
		public Type Type {
			get {
				if (null == _type) {
					_type = StyleSheet.GetPropertyInfo(_index).ValueType;
				}
				return _type;
			}
		}
	}
}
